package lesson07.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2023/01/15  12:23
 */
public class Demo02 {
    public static void main(String[] args) {
        //创建大小为三个的线程池
        ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(3);
        for (int i = 0; i < 100; i++) {
            int taskId = i;
            newFixedThreadPool.submit(() -> {
                System.out.println("执行任务" + taskId + "...");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } );
        }
    }
}
